﻿using System;
using System.Windows.Forms;
using Autofac;
using ComputerVision.Data;
using ComputerVision.Data.Repositories;
using ComputerVision.Services;
using ComputerVision.Services.RoleService;
using ComputerVision.Services.User;

namespace ComputerVision
{
    internal static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            frmSplash.ShowSplashScreen();
            //Application.Run(new frmRegister());
            Application.Run(new frmLogin());
        }

        public static readonly IContainer Container = ConfigureContainer();
        private static IContainer ConfigureContainer()
        {
            var builder = new ContainerBuilder();
            //QuanHuyen
            builder.RegisterType<QuanHuyenService>().As<IService<QuanHuyen>>();
            builder.RegisterType<EntityRepository<QuanHuyen>>().As<IEntityRepository<QuanHuyen>>();
            //HinhThucDauTu
            builder.RegisterType<HinhThucDauTuService>().As<IService<HinhThucDauTu>>();
            builder.RegisterType<EntityRepository<HinhThucDauTu>>().As<IEntityRepository<HinhThucDauTu>>();
            //LoaiHinhHoatDong
            builder.RegisterType<LoaiHinhHoatDongService>().As<IService<LoaiHinhHoatDong>>();
            builder.RegisterType<EntityRepository<LoaiHinhHoatDong>>().As<IEntityRepository<LoaiHinhHoatDong>>();
            //LoaiCoSo
            builder.RegisterType<LoaiCoSoService>().As<IService<LoaiCoSo>>();
            builder.RegisterType<EntityRepository<LoaiCoSo>>().As<IEntityRepository<LoaiCoSo>>();
            //Phong
            builder.RegisterType<PhongService>().As<IService<Phong>>();
            builder.RegisterType<EntityRepository<Phong>>().As<IEntityRepository<Phong>>();
            //Nganh
            builder.RegisterType<NganhService>().As<IService<Nganh>>();
            builder.RegisterType<EntityRepository<Nganh>>().As<IEntityRepository<Nganh>>();
            //Doi
            builder.RegisterType<DoiService>().As<IService<Doi>>();
            builder.RegisterType<EntityRepository<Doi>>().As<IEntityRepository<Doi>>();
            //CanBo
            builder.RegisterType<CanBoService>().As<IService<CanBo>>();
            builder.RegisterType<EntityRepository<CanBo>>().As<IEntityRepository<CanBo>>();
            //CapQuanLyHanhChinh
            builder.RegisterType<CapQuanLyHanhChinhService>().As<IService<CapQuanLyHanhChinh>>();
            builder.RegisterType<EntityRepository<CapQuanLyHanhChinh>>().As<IEntityRepository<CapQuanLyHanhChinh>>();
            //ThanhPhanKinhTe
            builder.RegisterType<ThanhPhanKinhTeService>().As<IService<ThanhPhanKinhTe>>();
            builder.RegisterType<EntityRepository<ThanhPhanKinhTe>>().As<IEntityRepository<ThanhPhanKinhTe>>();
            //VanBanThamDuyetPCCC
            builder.RegisterType<VanBanThamDuyetPCCCService>().As<IService<VanBanThamDuyetPCCC>>();
            builder.RegisterType<EntityRepository<VanBanThamDuyetPCCC>>().As<IEntityRepository<VanBanThamDuyetPCCC>>();
            //CoQuanCapVanBanThamDuyet
            builder.RegisterType<CoQuanCapVanBanThamDuyetService>().As<IService<CoQuanCapVanBanThamDuyet>>();
            builder.RegisterType<EntityRepository<CoQuanCapVanBanThamDuyet>>().As<IEntityRepository<CoQuanCapVanBanThamDuyet>>();
            //ThamDuyetPCCC
            builder.RegisterType<ThamDuyetPCCCService>().As<IService<ThamDuyetPCCC>>();
            builder.RegisterType<EntityRepository<ThamDuyetPCCC>>().As<IEntityRepository<ThamDuyetPCCC>>();
            //CoQuanQuanLyPCCC
            builder.RegisterType<CoQuanQuanLyPCCCService>().As<IService<CoQuanQuanLyPCCC>>();
            builder.RegisterType<EntityRepository<CoQuanQuanLyPCCC>>().As<IEntityRepository<CoQuanQuanLyPCCC>>();
            //BacChiuLua
            builder.RegisterType<BacChiuLuaService>().As<IService<BacChiuLua>>();
            builder.RegisterType<EntityRepository<BacChiuLua>>().As<IEntityRepository<BacChiuLua>>();
            //HangSanXuat
            builder.RegisterType<HangSanXuatService>().As<IService<HangSanXuat>>();
            builder.RegisterType<EntityRepository<HangSanXuat>>().As<IEntityRepository<HangSanXuat>>();
            //HangMuc
            builder.RegisterType<HangMucService>().As<IService<HangMuc>>();
            builder.RegisterType<EntityRepository<HangMuc>>().As<IEntityRepository<HangMuc>>();
            //HangMuc
            builder.RegisterType<PhieuDieuTraCoSoService>().As<IService<PhieuDieuTraCoSo>>();
            builder.RegisterType<EntityRepository<PhieuDieuTraCoSo>>().As<IEntityRepository<PhieuDieuTraCoSo>>();
            //PhuongTienCoSo
            builder.RegisterType<PhuongTienCoSoService>().As<IService<PhuongTienCoSo>>();
            builder.RegisterType<EntityRepository<PhuongTienCoSo>>().As<IEntityRepository<PhuongTienCoSo>>();
            //NhomPhuongTien
            builder.RegisterType<NhomPhuongTienService>().As<IService<NhomPhuongTien>>();
            builder.RegisterType<EntityRepository<NhomPhuongTien>>().As<IEntityRepository<NhomPhuongTien>>();
            //PhanLoaiChiTietPhuongTien
            builder.RegisterType<PhanLoaiChiTietPhuongTienService>().As<IService<PhanLoaiChiTietPhuongTien>>();
            builder.RegisterType<EntityRepository<PhanLoaiChiTietPhuongTien>>().As<IEntityRepository<PhanLoaiChiTietPhuongTien>>();
            //NguonNuoc
            builder.RegisterType<NguonNuocService>().As<IService<NguonNuoc>>();
            builder.RegisterType<EntityRepository<NguonNuoc>>().As<IEntityRepository<NguonNuoc>>();
            //LoaiNguonNuoc
            builder.RegisterType<LoaiNguonNuocService>().As<IService<LoaiNguonNuoc>>();
            builder.RegisterType<EntityRepository<LoaiNguonNuoc>>().As<IEntityRepository<LoaiNguonNuoc>>();
            //PhanLoaiChiTietNguonNuoc
            builder.RegisterType<PhanLoaiChiTietNguonNuocService>().As<IService<PhanLoaiChiTietNguonNuoc>>();
            builder.RegisterType<EntityRepository<PhanLoaiChiTietNguonNuoc>>().As<IEntityRepository<PhanLoaiChiTietNguonNuoc>>();
            //TuyenTruyenHuanLuyen
            builder.RegisterType<TuyenTruyenHuanLuyenService>().As<IService<TuyenTruyenHuanLuyen>>();
            builder.RegisterType<EntityRepository<TuyenTruyenHuanLuyen>>().As<IEntityRepository<TuyenTruyenHuanLuyen>>();
            //KiemTraAnToan
            builder.RegisterType<KiemTraAnToanService>().As<IService<KiemTraAnToan>>();
            builder.RegisterType<EntityRepository<KiemTraAnToan>>().As<IEntityRepository<KiemTraAnToan>>();
            //PhuongAnChuaChay
            builder.RegisterType<PhuongAnChuaChayService>().As<IService<PhuongAnChuaChay>>();
            builder.RegisterType<EntityRepository<PhuongAnChuaChay>>().As<IEntityRepository<PhuongAnChuaChay>>();
            //LucLuongThucTap
            builder.RegisterType<LucLuongThucTapService>().As<IService<LucLuongThucTap>>();
            builder.RegisterType<EntityRepository<LucLuongThucTap>>().As<IEntityRepository<LucLuongThucTap>>();
            //PhuongTienThucTap
            builder.RegisterType<PhuongTienThucTapService>().As<IService<PhuongTienThucTap>>();
            builder.RegisterType<EntityRepository<PhuongTienThucTap>>().As<IEntityRepository<PhuongTienThucTap>>();
            //NhomHanhVi
            builder.RegisterType<NhomHanhViService>().As<IService<NhomHanhVi>>();
            builder.RegisterType<EntityRepository<NhomHanhVi>>().As<IEntityRepository<NhomHanhVi>>();
            //XuLyViPham
            builder.RegisterType<XuLyViPhamService>().As<IService<XuLyViPham>>();
            builder.RegisterType<EntityRepository<XuLyViPham>>().As<IEntityRepository<XuLyViPham>>();
            //User Service
            builder.RegisterType<UserService>().As<IUserService<aspnet_Users>>();
            builder.RegisterType<EntityRepository<aspnet_Users>>().As<IEntityRepository<aspnet_Users>>();
            //Roles Service
            builder.RegisterType<RoleService>().As<IService<aspnet_Roles>>();
            builder.RegisterType<EntityRepository<aspnet_Roles>>().As<IEntityRepository<aspnet_Roles>>();
            //Set Context
            builder.Register(c => new QuanLyThongTinCoSoContext()).As<IEntitiesContext>();
            return builder.Build();
        }
    }
}